<%--
  Created by IntelliJ IDEA.
  User: a8945
  Date: 2019-07-15
  Time: 15:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<head>
    <title>发送信息</title>
    <link rel="stylesheet" href="<%=basePath%>css/bootstrap.min.css">
</head>
<body>
<input type="text" id="userName" >
<button onclick="connect()">连接</button>


<script>
    var ws = null;
    var userName = $("#userName").val();
    function connect() {
        if (userName != null) {
            if ('WebSocket' in window) {
                ws = new WebSocket("ws://127.0.0.1:8080/LIIMP/socketServer/" + $("#userName").val());
            } else {
                alert("该浏览器不支持WebSocket！请更换浏览器重新打开！")
            }
            ws.onmessage = function (evt) {
                console.log(evt.data)
            };

            ws.onclose = function (ev) {
                console.log("连接关闭！");
            };

            ws.onopen = function (ev) {
                console.log("连接成功！");
            };
        }
        else{
            alert("用户名为空！")
        }
    }

</script>
<script src="<%=basePath%>js/jquery-3.4.1.min.js"></script>
<script src="<%=basePath%>js/bootstrap.min.js"></script>
</body>
</html>
